/*
 * @version: 1.0
 * @Author: zhl
 * @Date: 2021-09-10 13:45:25
 * @LastEditors: zhl
 * @LastEditTime: 2021-09-26 13:28:21
 * @Description: 文件实现描述
 */

#include "Client-APDU.h"
#include "GET-Request.h"
#include "GET-Response.h"
#include "CLogger.h"



Client_APDU Client_APDU::c_client_apdu; 


Client_APDU::Client_APDU(/* args */)
{

}

Client_APDU::~Client_APDU()
{

}

Client_APDU *Client_APDU::getInstance(){
    return &c_client_apdu;
}

int Client_APDU::get_request_assemble(std::shared_ptr<CConfigManager> cm, TASK_PARAMS *task_params,  uint8_t *apdu, int len){

    if((NULL == task_params) || (task_params->items.empty()) || (NULL == apdu) || (1 > len)){
        return -1;
    }
    int offset = 0;
    *((uint8_t *)apdu) = CLIENT_GET_REQUEST;
    offset += sizeof(APDU_TAG_TYPE);
    int ret = GETRequest::getInstance()->get_request(cm, task_params, apdu+offset, len-offset);
    if(0 < ret){
        offset += ret;
        *(apdu+offset) = 0;
        return (offset+1);
    }
    return -1;
}